import Vue from "vue";
import VueRouter from "vue-router";

import Basicmeun from "@/views/Basicmeun";

import table from "@/views/table/tableselect.vue";
// import modules from "./modules"; // 路由模块searchTable

const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err);
};

Vue.use(VueRouter);

const router = new VueRouter({
  mode: "hash",
  base: process.env.BASE_URL,
  routes: [
    {
      path: "/",
      name: "root",
      component: Basicmeun,
      meta: { title: "首页" },
      children: [
        // modules
        {
          path: "otable",
          name: "otable",
          meta: { title: "报告修改" },
          component: table
        }
       
        
      ]
    }
  ],
  // vue-router优化：当切换到新路由时，页面滚到顶部
  // TODO 后面会移到hook/afterEach/scroll.js去处理
  // @see https://router.vuejs.org/zh/guide/advanced/scroll-behavior.html#%E6%BB%9A%E5%8A%A8%E8%A1%8C%E4%B8%BA
  // eslint-disable-next-line no-unused-vars
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      // savedPosition is only available for popstate navigations.
      return savedPosition;
    } else {
      const position = {};
      // new navigation scroll to anchor by returning the selector
      if (to.hash) {
        position.selector = to.hash;
      }
      // check if any matched route config has meta that requires scrolling to top
      if (to.matched.some(m => m.meta.scrollToTop)) {
        // cords will be used if no selector is provided, or if the selector didn't match any element.
        position.x = 0;
        position.y = 0;
      }
      // if the returned position is falsy or an empty object, will retain current scroll position.
      return position;
    }
  }
});

// 应用钩子

export default router;
